/**
 * 
 */
package com.alex.structs2.action;

import java.io.IOException;
import java.util.List;

import net.sf.json.JSONArray;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import com.alex.hibernate.domain.User;
import com.alex.hibernate.manager.UserManager;
import com.opensymphony.xwork2.ActionSupport;

/**
 * @author alex
 */
@Namespace("/user")
public class UserAction extends ActionSupport {

	private static final long serialVersionUID = 2949025641758171231L;
	
	@Autowired
	@Qualifier(value="userManagerImplHibernate")
	UserManager userMgr;
	
	public void pagedQuery() {
		List<User> users = userMgr.getAll();
		String resultJsonStr = JSONArray.fromObject(users).toString();
		StringBuffer resultStr = new StringBuffer("{totalProperty:").append(users.size()).append(",result:")
			.append(resultJsonStr).append("}");
		
		try {
			ServletActionContext.getResponse().getWriter().write(resultStr.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
